<!DOCTYPE html>
<html lang="en">
<head>
   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <meta http-equiv="X-UA-Compatible" content="ie=edge">
   <title>Document</title>
</head>
<body>
   <script>
      var arr = [4,3,2,7,8,2,3,1];
      var arr1 = [1,8,9];
      var arr2 = [2,4,9];
      function res(dom){
         // 先找到数组中的最大值
         var max = dom[0];
         for(var i =0;i<dom.length;i++){
            if(max < dom[i]){
               max = dom[i];
            }
         }
         // console.log(max);
         // 利用1~max之间查没有的值然后添加进去
         var len = dom.length;
         for(var i=1;i<max;i++){
            if(dom.indexOf(i) === -1){
               dom.push(i);
            }
         }
         var num = dom.slice(len,dom.length);
         console.log(num);
      }
      res(arr);
      res(arr1);
      res(arr2);
   </script>
</body>
</html>